import * as SecureStore from 'expo-secure-store';

const KEY_LAST_CHANNEL = 'last_pay_channel_v1';

export type PayChannel = 'wechat' | 'alipay';

export async function getLastPayChannel(): Promise<PayChannel | null> {
  try {
    const v = await SecureStore.getItemAsync(KEY_LAST_CHANNEL);
    if (!v) return null;
    if (v === 'wechat' || v === 'alipay') return v;
    return null;
  } catch {
    return null;
  }
}

export async function setLastPayChannel(channel: PayChannel) {
  try {
    await SecureStore.setItemAsync(KEY_LAST_CHANNEL, channel);
  } catch {}
}

